//axios
const axios = require('axios')
const cheerio = require('cheerio')
const download = require('download');
const url = 'https://www.toopic.cn/4kbz/?q=--147--.html'
const url2 = 'https://www.toopic.cn/4kbz/?q=--147--.html&page=2'
const sendApi = async () => {
    try {
        const { data } = await axios.get(url2)
        const $ = cheerio.load(data)
        let imgs = Array.prototype.map.call($('.pic-list li .bd img'), item => {
            // 处理中文为base64   encodeURI
            return 'https://www.toopic.cn/' + encodeURI($(item).attr('data-original'))
        })
        Promise.all(imgs.map(url => download(url, 'dist1'))).then(() => {
            console.log('下载完成')
        })
    } catch (err) { }
}

sendApi();